package main

import (
	"fmt"
)

func main() {
	nums := []int{2, 3, 4, 3}
	//arr :=twoSum(nums,6)
	//fmt.Println(arr)

	fmt.Println(twoSum2(nums, 6))

}

//func twoSum(nums []int, target int) []int {
//
//	save := []int{0, 0}
//	for i := 0; i < len(nums); i++ {
//		for j := i + 1; j < len(nums); j++ {
//			if nums[i]+nums[j] == target {
//				save[0] = i
//				save[1] = j
//			}
//
//		}
//	}
//
//	return save
//}

func twoSum2(nums []int, target int) []int {
	save := map[int]int{}

	for i, x := range nums {
		if p, ok := save[target-x]; ok {
			return []int{p, i}
		}
		save[x] = i
	}
	return nil
}
